<template>
  <!-- html -->
  <div class="person">
    <h1>情况1，监视【ref】定义的【基本类型数据】</h1>
    <h2>当前求和为{{ sum }}</h2>
    <button @click="changeSum">点我sum+1</button>
  </div>
</template>

<script lang="ts" setup name="Person">
import { ref, watch } from "vue";
let sum = ref(0);

function changeSum() {
  sum.value += 1;
}

//监视  sum是ref定义的数据 不要加value
const stopWatch = watch(sum, (newValue, oldValue) => {
  console.log("sum变化了", newValue, oldValue);
  if (newValue >= 10) {
    stopWatch(); //解除监视
  }
});
</script>

<style scoped>
/* 样式 */
.person {
  background-color: skyblue;
  box-shadow: 0 0 10px;
  border-radius: 10px;
  padding: 20px;
}
button {
  margin: 0 5px;
}
</style>
